import 'package:casdon/common/state/common_net_status.dart';
import 'package:casdon/modules/login/domain/states/login_code_state.dart';
import 'package:casdon/modules/login/domain/states/login_state.dart';

class LoginAppleState extends LoginState {
  final String? socialCode;
  final String? socialState;
  final String? account; // 绑定账户时使用
  final String? code; // 绑定账户时使用
  final SendCodeSource source;

  LoginAppleState({
    this.socialCode,
    this.socialState,
    this.account,
    this.code,
    required super.status,
    required super.version,
    super.agreed,
    super.message,
    super.errorCode, // 改为可空
    this.source = SendCodeSource.accountPage,
  });

  static LoginAppleState initial() => LoginAppleState(
    status: CommonNetStatus.idle,
    version: 1,
    agreed: false,
    message: null,
    errorCode: null,
    socialCode: null,
    socialState: null,
    account: null,
    code: null,
    source: SendCodeSource.accountPage,
  );

  // ✅ 私有标记对象
  static const Object _sentinel = Object();

  @override
  LoginAppleState copyWith({
    Object? status = _sentinel,
    Object? message = _sentinel,
    Object? version = _sentinel,
    Object? agreed = _sentinel,
    Object? errorCode = _sentinel,
    Object? socialCode = _sentinel,
    Object? socialState = _sentinel,
    Object? account = _sentinel,
    Object? code = _sentinel,
    Object? source = _sentinel,
  }) {
    return LoginAppleState(
      status: status == _sentinel
          ? this.status
          : status as CommonNetStatus? ?? this.status,
      message: message == _sentinel ? this.message : message as String?,
      version: version == _sentinel
          ? this.version
          : version as int? ?? this.version,
      agreed: agreed == _sentinel
          ? this.agreed
          : agreed as bool? ?? this.agreed,
      errorCode: errorCode == _sentinel ? this.errorCode : errorCode as String?,
      socialCode: socialCode == _sentinel
          ? this.socialCode
          : socialCode as String?,
      socialState: socialState == _sentinel
          ? this.socialState
          : socialState as String?,
      account: account == _sentinel ? this.account : account as String?,
      code: code == _sentinel ? this.code : code as String?,
      source: source == _sentinel ? this.source : source as SendCodeSource,
    );
  }
}
